package novel.front.novellist.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import novel.common.page.PageInfo;
import novel.common.page.PageParam;
import novel.common.utils.DateUtils;
import novel.front.novellist.dao.AppsoMapper;
import novel.front.novellist.dao.KuaixunMapper;
import novel.front.novellist.entity.Appso;
import novel.front.novellist.entity.Kuaixun;
import novel.front.novellist.service.KuaixunService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service("KuaixunService")
public class KuaixunServiceImpl implements KuaixunService {
    @Resource
    private KuaixunMapper kuaixunMapper;

    @Resource
    private AppsoMapper appsoMapper;


    @Override
    public void save(Kuaixun kuaixun) {
        kuaixunMapper.insertSelective(kuaixun);
    }

    @Override
    public PageInfo<Kuaixun> getListByPage(Kuaixun kuaixun, PageParam pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        List<Kuaixun> list=kuaixunMapper.searchKuaixun(kuaixun);
        for (Kuaixun k : list) {
            k.setTime(DateUtils.getBeforeTime(k.getPublicshAt()));
        }
        return new PageInfo<Kuaixun>(list);
    }

    @Override
    public List<Kuaixun> getList(Kuaixun kuaixun) {
        return kuaixunMapper.searchKuaixun(kuaixun);
    }

    @Override
    public PageInfo<Appso> getAppListByPage(Appso appso, PageParam pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        List<Appso> list = appsoMapper.selectByExample(appso);
        for (Appso k : list) {
            k.setPublished_at(DateUtils.getBeforeTime(k.getPublished_at()));
        }
        return new PageInfo<Appso>(list);
    }
}
